package com.bw.medical.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bw.medical.dao.TbDiagnoseDao;
import com.bw.medical.entity.TbDepartmentEntity;
import com.bw.medical.vo.Cha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bw.medical.entity.TbDiagnoseEntity;
import com.bw.medical.service.TbDiagnoseService;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.R;



/**
 * 诊断表 
 *
 * @author wj
 * @email sunlightcs@gmail.com
 * @date 2021-08-14 18:10:33
 */
@RestController
@RequestMapping("medical/tbdiagnose")
public class TbDiagnoseController {
    @Autowired
    private TbDiagnoseService tbDiagnoseService;
    @Autowired
    private TbDiagnoseDao tbDiagnoseDao;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        IPage<TbDiagnoseEntity> page=tbDiagnoseService.getList(params);
        PageUtils pageUtils = new PageUtils(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getPages());
        return R.ok().put("page", pageUtils);
    }

    @RequestMapping("plist")
    public R plist(@RequestParam Map<String, Object> params){
        IPage<Cha> page=tbDiagnoseService.getPlist(params);
        PageUtils pageUtils = new PageUtils(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getPages());
        return R.ok().put("page", pageUtils);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{reportId}")
    public R info(@PathVariable("reportId") Integer reportId){
		TbDiagnoseEntity tbDiagnose = tbDiagnoseService.getById(reportId);
        return R.ok().put("tbDiagnose", tbDiagnose);
    }
    /**
     * 查看患者诊断结果
     */
    @RequestMapping("/k3")
    public TbDiagnoseEntity k3(@RequestParam Map<String, Object> params){
        TbDiagnoseEntity tbDiagnoseEntity = tbDiagnoseDao.selectOne(new QueryWrapper<TbDiagnoseEntity>()
                .eq("clinical_id", Integer.valueOf(params.get("clinicalId").toString()))
                .eq("patient_id", Integer.valueOf(params.get("patientId").toString()))
                .eq("docter_id", Integer.valueOf(params.get("docterId").toString())));
    return tbDiagnoseEntity;
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbDiagnoseEntity tbDiagnose){
		tbDiagnoseService.save(tbDiagnose);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TbDiagnoseEntity tbDiagnose){
		tbDiagnoseService.updateById(tbDiagnose);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] reportIds){
		tbDiagnoseService.removeByIds(Arrays.asList(reportIds));

        return R.ok();
    }

}
